function isChinese(aa) {
	var a = aa;
	var pattern = /^[\u4E00-\u9FA5]+$/;
	return (pattern.test(a));
}
function trim(str) {
	return rtrim(ltrim(str));
}
function equals(str1, str2) {
	if (str1 == str2) {
		return true;
	}
	return false;
}
function ltrim(s) {
	if (s == null)
		return "";
	var whitespace = new String(" \t\n\r");
	var str = new String(s);
	if (whitespace.indexOf(str.charAt(0)) != -1) {
		var j = 0, i = str.length;
		while (j < i && whitespace.indexOf(str.charAt(j)) != -1) {
			j++;
		}
		str = str.substring(j, i);
	}
	return str;
}


//验证银行卡号
function luhmCheck(bankno){
		if (bankno.length < 16 || bankno.length > 19) {
			//$("#banknoInfo").html("银行卡号长度必须在16到19之间");
			return false;
		}
		var num = /^\d*$/;  //全数字
		if (!num.exec(bankno)) {
			//$("#banknoInfo").html("银行卡号必须全为数字");
			return false;
		}
		//开头6位
		var strBin="10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";    
		if (strBin.indexOf(bankno.substring(0, 2))== -1) {
			//$("#banknoInfo").html("银行卡号开头6位不符合规范");
			return false;
		}
        var lastNum=bankno.substr(bankno.length-1,1);//取出最后一位（与luhm进行比较）
    
        var first15Num=bankno.substr(0,bankno.length-1);//前15或18位
        var newArr=new Array();
        for(var i=first15Num.length-1;i>-1;i--){    //前15或18位倒序存进数组
            newArr.push(first15Num.substr(i,1));
        }
        var arrJiShu=new Array();  //奇数位*2的积 <9
        var arrJiShu2=new Array(); //奇数位*2的积 >9
        
        var arrOuShu=new Array();  //偶数位数组
        for(var j=0;j<newArr.length;j++){
            if((j+1)%2==1){//奇数位
                if(parseInt(newArr[j])*2<9)
                arrJiShu.push(parseInt(newArr[j])*2);
                else
                arrJiShu2.push(parseInt(newArr[j])*2);
            }
            else //偶数位
            arrOuShu.push(newArr[j]);
        }
        
        var jishu_child1=new Array();//奇数位*2 >9 的分割之后的数组个位数
        var jishu_child2=new Array();//奇数位*2 >9 的分割之后的数组十位数
        for(var h=0;h<arrJiShu2.length;h++){
            jishu_child1.push(parseInt(arrJiShu2[h])%10);
            jishu_child2.push(parseInt(arrJiShu2[h])/10);
        }        
        
        var sumJiShu=0; //奇数位*2 < 9 的数组之和
        var sumOuShu=0; //偶数位数组之和
        var sumJiShuChild1=0; //奇数位*2 >9 的分割之后的数组个位数之和
        var sumJiShuChild2=0; //奇数位*2 >9 的分割之后的数组十位数之和
        var sumTotal=0;
        for(var m=0;m<arrJiShu.length;m++){
            sumJiShu=sumJiShu+parseInt(arrJiShu[m]);
        }
        
        for(var n=0;n<arrOuShu.length;n++){
            sumOuShu=sumOuShu+parseInt(arrOuShu[n]);
        }
        
        for(var p=0;p<jishu_child1.length;p++){
            sumJiShuChild1=sumJiShuChild1+parseInt(jishu_child1[p]);
            sumJiShuChild2=sumJiShuChild2+parseInt(jishu_child2[p]);
        }      
        //计算总和
        sumTotal=parseInt(sumJiShu)+parseInt(sumOuShu)+parseInt(sumJiShuChild1)+parseInt(sumJiShuChild2);
        
        //计算Luhm值
        var k= parseInt(sumTotal)%10==0?10:parseInt(sumTotal)%10;        
        var luhm= 10-k;
        
        if(lastNum==luhm){
        $("#banknoInfo").html("Luhm验证通过");
        return true;
        }
        else{
        $("#banknoInfo").html("银行卡号必须符合Luhm校验");
        return false;
        }        
    }


function isCardNo(card)  
{  
   // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
   var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;  
   if(reg.test(card) === false)  
   {  
       return  false;  
   }  else{
	   return  true; 
   }
  
}

function rtrim(s) {
	if (s == null)
		return "";
	var whitespace = new String(" \t\n\r");
	var str = new String(s);
	if (whitespace.indexOf(str.charAt(str.length - 1)) != -1) {
		var i = str.length - 1;
		while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1) {
			i--;
		}
		str = str.substring(0, i + 1);
	}
	return str;
}

function isEmpty(s) {
	if (s == null || trim(s) == "")
		return true;
	return false;
}

function isInt(s, sign) {
	if (isEmpty(s))
		return (arguments.length == 2 && sign == true);
	var re = new RegExp("^-?\\d+$");
	return re.test(s);
}

function isFloat(s, sign) {
	if (isEmpty(s))
		return (arguments.length == 2 && sign == true);
	var re = new RegExp("^-?\\d+\\.?\\d*$");
	return re.test(s);
}

function isDigit(s, sign) {
	if (isEmpty(s))
		return (arguments.length == 2 && sign == true);
	var re = new RegExp("^-?\\d+\\.?$");
	return re.test(s);
}

function isChar(s, sign) {
	if (isEmpty(s))
		return (arguments.length == 2 && sign == true);
	var re = new RegExp("^[A-Za-z0-9_]*$");
	return re.test(s);
}

function isEmail(yx) {
	var reyx = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	return (reyx.test(yx));

}
function isQq(yx) {
	var reyx = /^\d{5,10}$/;
	return (reyx.test(yx));
	
}
//以http开头
function isHttp(yx) {
	var reyx = /^http:\/\//;
	return (reyx.test(yx));
	
}

function isMobile(yx) {
	var reyx = /^[1][3,5,8][0-9]{9}$/;
	return (reyx.test(yx));
}

function isPhone(yx) {
	var reyx = /^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
	return (reyx.test(yx));
}

function isPassWord(yx) {
	var reyx = /^[a-zA-Z0-9]{6,}$/;
	return (reyx.test(yx));
}

function isEqual(one, two) {
	if (!isFloat(one) && !isFloat(two))
		return false;
	var p1 = parseFloat(one);
	var p2 = parseFloat(two);
	return (p1 == p2);
}

function isGreaterThan(one, two) {
	if (!isFloat(one) && !isFloat(two))
		return false;
	var p1 = parseFloat(one);
	var p2 = parseFloat(two);
	return (p1 > p2);
}

function isGreaterEqual(one, two) {
	if (!isFloat(one) && !isFloat(two))
		return false;
	var p1 = parseFloat(one);
	var p2 = parseFloat(two);
	return (p1 >= p2);
}

function isNumber(obj) {
	if (isNaN(obj.value)) {

		obj.focus();

		return false;
	} else {

		return true;
	}
}
function isNumberValue(numberValue) {
	if (isNaN(numberValue)) {
		return false;
	} else {
		return true;
	}
}

function isOnlyNum(strSrc) {
	var strNum = "0123456789";
	strSrc = trim(strSrc);
	var len = strSrc.length;
	if (len == 0) {
		return false;
	}
	for (var i = 0; i < len; i++) {
		if (strNum.indexOf(strSrc.charAt(i)) < 0) {
			return false;
		}
	}
	return true;
}

function isNumForString(strSrc) {
	var strNum = "0123456789-.";
	strSrc = trim(strSrc);
	var len = strSrc.length;
	if (len == 0) {
		return false;
	}
	for (var i = 0; i < len; i++) {
		if (strNum.indexOf(strSrc.charAt(i)) < 0) {
			return false;
		}
	}
	return true;
}

function isOnlyNumChar(strSrc) {
	var strNum = "0123456789";
	strSrc = trim(strSrc);
	var len = strSrc.length;
	if (len == 0) {
		return false;
	}
	for (var i = 0; i < len; i++) {
		if (strNum.indexOf(strSrc.charAt(i)) < 0) {
			return false;
		}
	}
	return true;
}

function getStringLength(str) {
	str = trim(str);
	var len = 0;
	for (i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) > 256) {
			len += 2;
		} else {
			len++;
		}
	}
	return len;
}
// ----------------------------------------------------------------------
// <summary>
// 扩展jQuery方法
// </summary>
// ----------------------------------------------------------------------
$(function() {
	// 文本框只能输入数字(包括小数)，并屏蔽输入法和粘贴
	$.fn.cost = function() {
		$(this).css("ime-mode", "disabled");
		this.bind("keypress", function(e) {
			var code = (e.keyCode ? e.keyCode : e.which); // 兼容火狐 IE
			if (!$.support.msie && (e.keyCode == 0x8)) // 火狐下 不能使用退格键
			{
				return;
			}
			return code >= 48 && code <= 57 || code == 46;
		});
		this.bind("blur", function() {
			if (this.value.lastIndexOf(".") == (this.value.length - 1)) {
				this.value = this.value.substr(0, this.value.length - 1);
			} else if (isNaN(this.value)) {
				this.value = " ";
			}
		});
		this.bind("paste", function() {
			var s = clipboardData.getData('text');
			if (!/\D/.test(s))
				;
			value = s.replace(/^0*/, '');
			return false;
		});
		this.bind("dragenter", function() {
			return false;
		}); // 只允许输入数字，小数点
		this.bind("keyup", function() {
			// 先把非数字的都替换掉，除了数字和.
			this.value = this.value.replace(/[^\d.]/g, "");
			// 必须保证第一个为数字而不是.
			this.value = this.value.replace(/^\./g, "");
			// 保证只有出现一个.而没有多个.
			this.value = this.value.replace(/\.{2,}/g, ".");
			// 保证.只出现一次，而不能出现两次以上
			this.value = this.value.replace(".", "$#$").replace(/\./g, "")
					.replace("$#$", ".");
		});
	};
	// 文本框只能输入数字(不包括小数)，并屏蔽输入法和粘贴
	$.fn.numeral = function() {
		$(this).css("ime-mode", "disabled");
		this.bind("keypress", function(e) {
			var code = (e.keyCode ? e.keyCode : e.which); // 兼容火狐 IE
			if (!$.support.msie && (e.keyCode == 0x8)) { // 火狐下不能使用退格键
				return;
			}
			return code >= 48 && code <= 57;
		});
		this.bind("paste", function() {
			var s = clipboardData.getData('text');
			if (!/\D|^0/g.test(s))
				;
			value = s.replace(/\D|^0/g, '');
			return false;
		});
		this.bind("keyup", function() {
			if (/\D|^0/g.test(this.value)) {
				this.value = this.value.replace(/\D|^0/g, '');
			}
		});
	};
});